<?php
//require_once ($_SERVER['DOCUMENT_ROOT']."/Auditing/business/InsertRule.php");

Class UpdateRule{


	var $rule_name;
	var $flag;
	var $field;
	var $logic;
	var $text_value;
	var $rule_meta_data_id;
	var $insertObj;

	function UpdateRule($rule_name,$flag,$field,$logic,$text_value,$rule_meta_data_id){

		$this->rule_name = $rule_name;
		$this->flag = $flag;
		$this->field = $field;
		$this->logic = $logic;
		$this->text_value = $text_value;
		$this->rule_meta_data_id = $rule_meta_data_id;
		$this->insertObj = new InsertRule($rule_name,$flag,$field,$logic,$text_value);

	}
	
	function saveRule(){
		
		$returnVal = 0;
		$strQuery = "update ota_rulemetadata set description='".$this->rule_name."' ,flag_id = ".$this->flag.
		" where rule_meta_data_id=".$this->rule_meta_data_id;
		
		//echo $strQuery;
		
		
		$result = mysql_query($strQuery);

		if (!$result) {

			die('Invalid query: ' . mysql_error());
		}
		else {

			$strQuery = "delete from ota_ruleset where rule_meta_data_id = ".$this->rule_meta_data_id;
			//echo $strQuery;
			$result = mysql_query($strQuery);

			if (!$result) {
					
				die('Invalid query: ' . mysql_error());
			}
			else {
				$returnVal = $this->insertObj->insertIntoRuleSet($this->field,$this->rule_meta_data_id,$this->logic,$this->text_value);

			}
		}

		return $returnVal;
	}

}
?>